const fs = require('fs')

const getSpace = (num) => new Array(num).fill('  ')
const ignore = ['.spray', 'node_modules']
let str = ''

function walk(dir, space) {
  fs.readdirSync(dir).forEach(function (filename) {
    if (ignore.includes(filename)) {
      return
    }
    let path = dir + '/' + filename
    let stat = fs.statSync(path)
    const spc = getSpace(space)
    str += `${spc.join('')}${filename}\n`
    if (stat && stat.isDirectory()) {
      walk(path, space + 1)
    }
  })
}
walk(__dirname, 0)
fs.writeFileSync('file.txt', str)
